package com.guangzhi.weijianzhi.view;
/**
 * 用来解析数据
 */
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

import com.guangzhi.weijianzhi.R;

import android.app.Activity;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.Toast;

public class IndustryData{

	

	public static Map<String, List<ProvinceAndCity>> initData(Resources re) {
		// TODO Auto-generated method stub
		
		Map<String, List<ProvinceAndCity>> maps = null;
		List<String> shengs = new ArrayList<String>();
		List<ProvinceAndCity> lists =null;
		ProvinceAndCity city = null;
		
		//公司地址区域
				InputStream inputStream = re.openRawResource(
						R.raw.industryicategory);
				try {
					XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
					XmlPullParser parser = factory.newPullParser();
					parser.setInput(inputStream, "utf-8");
						String sheng="";
						
					int eventType = parser.getEventType();

					while (eventType != XmlPullParser.END_DOCUMENT) {

						
						switch (eventType) {

						case XmlPullParser.START_TAG:
							if (parser.getName().equals("IndustryCategory")) {
								maps = new HashMap<String, List<ProvinceAndCity>>();
							}else if(parser.getName().equals("p")){
								lists = new ArrayList<IndustryData.ProvinceAndCity>();
							}else if((parser.getName().equals("pn"))){
								sheng =parser.nextText();
							}else if(parser.getName().equals("c")){
								city = new ProvinceAndCity();
								String id = parser.getAttributeValue(0);
								city.id = id;
							}else if(parser.getName().equals("cn")){
								String name = parser.nextText();
								city.name = name;
							}

							break;

						case XmlPullParser.END_TAG:

							if (parser.getName().equals("c")) {
								lists.add(city);
								city =null;
							}else if(parser.getName().equals("p")){
								if(!"".equals(sheng)){
									maps.put(sheng, lists);
									shengs.add(sheng);
									sheng = "";
								}
								
								
							}

							break;
						}

						eventType = parser.next();
					}

				}  catch (Exception e) {
					e.printStackTrace();
				}
					return maps;
	}

	  public static class ProvinceAndCity{
		
		public String id;
		public String name;
	}

}
